package com.abcdefg.springmvc.demo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

@RequestMapping("Demo")
@RestController
public class Demo1 {

    @RequestMapping("r1")
    public String r1(String name){
        return "返回参数:"+name;
    }
    @RequestMapping("r2")
    public String r2(String name,Integer age){
        return "返回姓名:" + name + "返回年龄:"+ age;
    }
    @RequestMapping("r3")
    public String r3(Person person){
        return person.toString();
    }
    @RequestMapping("r5")
    public String r5(@RequestParam(value = "n",required = false) String name){
        return "返回参数" + name;
    }

    @RequestMapping("r6")
    public String r6(String[] str){
        return Arrays.toString(str);
    }
    @RequestMapping("r7")
    public String r7(@RequestParam ArrayList<String> array){
        return array.toString();
    }

    @RequestMapping("r8")
    public String r8(@RequestBody Person person){
        return person.toString();
    }
    @RequestMapping("/article/{id}/{he}")
    public String r9(@PathVariable Integer id, @PathVariable("he") String type){
        return id+":"+type;
    }
    @RequestMapping("r10")
    public String r10(@RequestPart("file") MultipartFile file) throws IOException {
        file.transferTo(new File("D:/Project/pic/tmp/"+ file.getOriginalFilename()));
        return  file.getOriginalFilename();
    }

}
